﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>修改学生信息</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script src="../Scripts/jquery-3.3.1.js"></script>
    <script src="../layui/layui.js" charset="utf-8"></script>
</head>
<body>
    
    <div class="layui-card">
        <div class="layui-card-header">修改密码</div>
        <div class="layui-card-body" pad15="">
          
          <div class="layui-form" lay-filter="">
            <div class="layui-form-item">
                <label class="layui-form-label">学号</label>
                <div class="layui-input-inline">
                  <input type="text" name="student_id"  readonly="" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">不可修改</div>
              </div>
            <div class="layui-form-item">
                
                  <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                      <input type="password" name="password" autocomplete="off" placeholder="请输入密码" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-inline">
                      <input type="password" name="passwordOnce"   autocomplete="off" placeholder="请输入确认密码" class="layui-input">
                    </div>
                  </div>
            
           
            </div>
          </div>
          
        </div>
      </div>
    <script>
        layui.use(['form', 'layedit', 'layer', 'jquery'], function ()
        {
            var form = layui.form,
                layedit = layui.layedit,
                layer = layui.layer,
                $ = layui.jquery;


            //专业
            var majorSet;
            $.ajax({
                url: '../operate/getSet.aspx',
                datatype: 'text',
                data: { "table": "tb_major" },
                success: function (res)
                {
                    //把数据填充到专业下拉框
                    majorSet = res;
                    var major = majorSet.split(',');
                    var html1 = '<dd lay-value="" class="layui-select-tips layui-this">直接选择或搜索选择</dd>';
                    var html2 = '<option value="" >直接选择或搜索选择</option>';
                    for (var i = 0; i < major.length; i++)
                    {
                        html1 += '<dd lay-value="' + i + '">' + major[i] + '</dd>';
                        html2 += '<option value="' + i + '">' + major[i] + '</option>';
                    }
                    var select = $(".majorSelect");
                    $(".majorSelect").next().children().eq(1).html(html1);//dd  是渲染代码
                    $(".majorSelect").html(html2); //option 选项代码
                    form.render();//没有写这个，操作后没有效果
                }
            });

            $.ajax({
                url: '../operate/getSet.aspx',
                datatype: 'text',
                data: { "table": "tb_major" },
                success: function (res)
                {
                    alert(res);
                }
                //填充数据

            });

            $("#submitBtn").click(function ()
            {
                //判断是否为空
                var para = {};
                para["table"] = "tb_student";
                var items = $(".layui-input");
                debugger;
                for (var i = 0; i < items.length ; i++)
                {
                    var key = items[i].name;
                    para[key] = items[i].value;
                }
                para['student_sex'] = $("input[type='radio'][name='student_sex']:checked").val();
                var a = $(".majorSelect")[0];
                var index = a.selectedIndex;
                para["major_name"] = a[index].text;
                delete para[""];
                alert(JSON.stringify(para));
                $.ajax({
                    url: '../operate/changeInfo.aspx',
                    data: para,
                    success: function (res)
                    {
                        if (res > 0)
                        {
                            layer.alert('修改成功', { icon: 1 });
                        }
                        else
                        {
                            layer.alert('修改失败', { icon: 6 });
                        }
                    }

                });
            });

            

        })
    </script>
    
</body>
</html>
